import { UserActonType } from '../actionTypes';
import { getToken } from '@/utils/auth';

const initialState = {
  token: getToken(),
  id: '',
  name: '',
  avatar: '',
  roles: [],
  permissions: [],
};

type ActionType = {
  type: string;
  payload?: any;
};

const userReducer = (state = initialState, action: ActionType): typeof initialState => {
  switch (action.type) {
    // login
    case UserActonType.LOGIN:
      return {
        ...state,
        ...action.payload,
      };
    case UserActonType.GET_INFO:
      return {
        ...state,
      };

    case UserActonType.LOGOUT:
      return {
        ...state,
      };
    default:
      return state;
  }
};

export default userReducer;
